home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / ixemul / include / sys / sem.h < prev    next >
C/C++ Source or Header  |  1997-10-28  |  5KB  |  188 lines

  1. /*    $NetBSD: sem.h,v 1.8 1996/02/09 18:25:29 christos Exp $    */
  2.  
  3. /*
  4.  * SVID compatible sem.h file
  5.  *
  6.  * Author:  Daniel Boulet
  7.  */
  8.  
  9. #ifndef _SYS_SEM_H_
  10. #define _SYS_SEM_H_
  11.  
  12. #include <sys/ipc.h>
  13.  
  14. struct sem {
  15.     u_short    semval;        /* semaphore value */
  16.     pid_t    sempid;        /* pid of last operation */
  17.     u_short    semncnt;    /* # awaiting semval > cval */
  18.     u_short    semzcnt;    /* # awaiting semval = 0 */
  19. };
  20.  
  21. struct semid_ds {
  22.     struct    ipc_perm sem_perm;    /* operation permission struct */
  23.     struct    sem *sem_base;    /* pointer to first semaphore in set */
  24.     u_short    sem_nsems;    /* number of sems in set */
  25.     time_t    sem_otime;    /* last operation time */
  26.     long    sem_pad1;    /* SVABI/386 says I need this here */
  27.     time_t    sem_ctime;    /* last change time */
  28.                     /* Times measured in secs since */
  29.                     /* 00:00:00 GMT, Jan. 1, 1970 */
  30.     long    sem_pad2;    /* SVABI/386 says I need this here */
  31.     long    sem_pad3[4];    /* SVABI/386 says I need this here */
  32. };
  33.  
  34. /*
  35.  * semop's sops parameter structure
  36.  */
  37. struct sembuf {
  38.     u_short    sem_num;    /* semaphore # */
  39.     short    sem_op;        /* semaphore operation */
  40.     short    sem_flg;    /* operation flags */
  41. };
  42. #define SEM_UNDO    010000
  43.  
  44. #define MAX_SOPS    5    /* maximum # of sembuf's per semop call */
  45.  
  46. /*
  47.  * semctl's arg parameter structure
  48.  */
  49. union semun {
  50.     int    val;        /* value for SETVAL */
  51.     struct    semid_ds *buf;    /* buffer for IPC_STAT & IPC_SET */
  52.     u_short    *array;        /* array for GETALL & SETALL */
  53. };
  54.  
  55. /*
  56.  * commands for semctl
  57.  */
  58. #define GETNCNT    3    /* Return the value of semncnt {READ} */
  59. #define GETPID    4    /* Return the value of sempid {READ} */
  60. #define GETVAL    5    /* Return the value of semval {READ} */
  61. #define GETALL    6    /* Return semvals into arg.array {READ} */
  62. #define GETZCNT    7    /* Return the value of semzcnt {READ} */
  63. #define SETVAL    8    /* Set the value of semval to arg.val {ALTER} */
  64. #define SETALL    9    /* Set semvals from arg.array {ALTER} */
  65.  
  66. #define GETSEMINFO 10    /* Return pointer to seminfo struct */
  67. #define GETSEMA 11    /* Return pointer to sema array */
  68. #define SEMLCK  12    /* Lock semaphore structs */
  69. #define SEMUNLK 13    /* Unlock semaphore structs */
  70.  
  71. #ifdef _KERNEL
  72. /*
  73.  * Kernel implementation stuff
  74.  */
  75. #define SEMVMX    32767        /* semaphore maximum value */
  76. #define SEMAEM    16384        /* adjust on exit max value */
  77.  
  78. /*
  79.  * Permissions
  80.  */
  81. #define SEM_A        0200    /* alter permission */
  82. #define SEM_R        0400    /* read permission */
  83.  
  84. /*
  85.  * Undo structure (one per process)
  86.  */
  87. struct sem_undo {
  88.     struct    sem_undo *un_next;    /* ptr to next active undo structure */
  89.     struct    Task *un_proc;        /* owner of this structure */
  90.     short    un_cnt;            /* # of active entries */
  91.     struct undo {
  92.         short    un_adjval;    /* adjust on exit values */
  93.         short    un_num;        /* semaphore # */
  94.         int    un_id;        /* semid */
  95.     } un_ent[1];            /* undo entries */
  96. };
  97.  
  98. /*
  99.  * semaphore info struct
  100.  */
  101. struct seminfo {
  102.     int    semmap,        /* # of entries in semaphore map */
  103.         semmni,        /* # of semaphore identifiers */
  104.         semmns,        /* # of semaphores in system */
  105.         semmnu,        /* # of undo structures in system */
  106.         semmsl,        /* max # of semaphores per id */
  107.         semopm,        /* max # of operations per semop call */
  108.         semume,        /* max # of undo entries per process */
  109.         semusz,        /* size in bytes of undo structure */
  110.         semvmx,        /* semaphore maximum value */
  111.         semaem;        /* adjust on exit max value */
  112. };
  113. //struct seminfo    seminfo;
  114.  
  115. /* internal "mode" bits */
  116. #define    SEM_ALLOC    01000    /* semaphore is allocated */
  117. #define    SEM_DEST    02000    /* semaphore will be destroyed on last detach */
  118.  
  119. /*
  120.  * Configuration parameters
  121.  */
  122. #ifndef SEMMNI
  123. #define SEMMNI    10        /* # of semaphore identifiers */
  124. #endif
  125. #ifndef SEMMNS
  126. #define SEMMNS    60        /* # of semaphores in system */
  127. #endif
  128. #ifndef SEMUME
  129. #define SEMUME    10        /* max # of undo entries per process */
  130. #endif
  131. #ifndef SEMMNU
  132. #define SEMMNU    30        /* # of undo structures in system */
  133. #endif
  134.  
  135. /* shouldn't need tuning */
  136. #ifndef SEMMAP
  137. #define SEMMAP    30        /* # of entries in semaphore map */
  138. #endif
  139. #ifndef SEMMSL
  140. #define SEMMSL    SEMMNS        /* max # of semaphores per id */
  141. #endif
  142. #ifndef SEMOPM
  143. #define SEMOPM    100        /* max # of operations per semop call */
  144. #endif
  145.  
  146. /* actual size of an undo structure */
  147. #define SEMUSZ    (sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME)
  148.  
  149. #if 0
  150. /*
  151.  * Structures allocated in machdep.c
  152.  */
  153. struct    semid_ds *sema;        /* semaphore id pool */
  154. struct    sem *sem;        /* semaphore pool */
  155. struct    map *semmap;        /* semaphore allocation map */
  156. struct    sem_undo *semu_list;    /* list of active undo structures */
  157. int    *semu;            /* undo structure pool */
  158. #endif
  159.  
  160. /*
  161.  * Macro to find a particular sem_undo vector
  162.  */
  163. #define SEMU(i)    ((struct sem_undo *)(((long)semu)+i * SEMUSZ))
  164.  
  165. /*
  166.  * Parameters to the semconfig system call
  167.  */
  168. #define    SEM_CONFIG_FREEZE    0    /* Freeze the semaphore facility. */
  169. #define    SEM_CONFIG_THAW        1    /* Thaw the semaphore facility. */
  170. #endif /* _KERNEL */
  171.  
  172. #ifndef _KERNEL
  173. #include <sys/cdefs.h>
  174.  
  175. __BEGIN_DECLS
  176. int semctl __P((int, int, int, union semun));
  177. int __semctl __P((int, int, int, union semun *));
  178. int semget __P((key_t, int, int));
  179. int semop __P((int, struct sembuf *, u_int));
  180. int semconfig __P((int));
  181. __END_DECLS
  182. #else
  183. void seminit __P((void));
  184. void semexit __P((struct Task *));
  185. #endif /* !_KERNEL */
  186.  
  187. #endif /* !_SEM_H_ */
  188.